"ui";

var ColoredButton = (function () {
    //继承ui.Widget
    util.extend(ColoredButton, ui.Widget);

    function ColoredButton() {
        //调用父类构造函数
        ui.Widget.call(this);
        //自定义属性color，定义按钮颜色
        this.defineAttr("color", (view, name, defaultGetter) => {
            return this._color;
        }, (view, name, value, defaultSetter) => {
            this._color = value;
            view.attr("backgroundTint", value);
        });

    }
    ColoredButton.prototype.render = function () {
        return(
        <button textSize="16sp" style="Widget.AppCompat.Button.Colored" w="*" h="auto" /> 
        );
    }

    ui.registerWidget("colored-button", ColoredButton);
    return ColoredButton;
})();
var color = "#009688";
ui.statusBarColor("#2F4F4F")
ui.layout(
    <drawer id="drawer" >
        <vertical>
            <appbar>
                <toolbar id="toolbar" paddingTop="5dp" title="好友bp模式903" bg="#2F4F4F" />
            </appbar>

            <viewpager id="viewpager">
                //这是聚划算界面
                <frame> //start
                    <ScrollView>
                        <vertical>
                            <Switch id="autoService" text="无障碍服务" checked="{{auto.service != null}}" padding="8 8 8 8" textSize="13sp" />
                            {/* <Switch id="overlayService" text="悬浮窗权限" checked="{{auto.service != null}}" padding="8 8 8 8"textSize="13sp" />  */}
                            <text textSize="13sp" id="networkTesttwo" textColor="#A020F0" margin="0 5" text="软件已默认校准淘宝时间！" />

                            <radiogroup orientation="horizontal">
                                <checkbox id="pay1" text="自动付款" />
                                <checkbox id="tijiao" text="检测提交价格" />
                                <checkbox id="bt1" text="隐藏密码" checked="false" />
                            </radiogroup>

                            <horizontal>
                                <text id="lianjie" text="请将BP链接发送至淘宝任意好友，再开始运行！如何获取链接请点击我！⬅" textColor="#A020F0" w="auto" />
                            </horizontal>


                            <horizontal>
                                <text textSize="13sp" textColor="black" text="提前抢购时间" />
                                <input id="delaytime_two" textColor="gray" inputType="number" text="700" w="80" />
                                <text textSize="13sp" textColor="black" text="毫秒" />
                            </horizontal>

                            <horizontal>
                                <text textSize="13sp" textColor="black" text="提交订单频率" />
                                <input id="interval" textColor="gray" inputType="number" text="100" w="80" />
                                <text textSize="13sp" textColor="black" text="毫秒" />
                            </horizontal>

                            <horizontal>
                                <text textSize="13sp" textColor="black" text="抢购持续时间" />
                                <input id="lastTime_two" textColor="gray" inputType="number" text="10" w="80" />
                                <text textSize="13sp" textColor="black" text="秒" />
                            </horizontal>

                            <horizontal>
                                <text textSize="14sp" textColor="black" text="商品价格不等于" />
                                <input id="password_7" textColor="gray" inputType="number|numberDecimal" text="10" w="80" />
                                <text textSize="14sp" textColor="black" text="元不提交" />
                            </horizontal>

                            <linear id="h" layout_gravity="center">
                                <horizontal>
                                    <text textSize="13sp" textColor="black" text="支付密码：" />
                                    <input id="password_1" textColor="gray" hint="*" w="45" />
                                    <input id="password_2" textColor="gray" hint="*" w="45" />
                                    <input id="password_3" textColor="gray" hint="*" w="45" />
                                    <input id="password_4" textColor="gray" hint="*" w="45" />
                                    <input id="password_5" textColor="gray" hint="*" w="45" />
                                    <input id="password_6" textColor="gray" hint="*" w="45" />
                                </horizontal>
                            </linear>

                            <text textSize="13sp" textColor="black" text="请输入抢购时间,格式为：2020/08/19 12:00:00" />
                            <input hint="请在这里输入抢购时间，格式必须正确。" textColor="gray" id="startTime_two" />
                            //定义按钮的大小颜色和文本
                            <colored-button id="ok_two" layout_gravity="center" color="#008B8B" text="开始运行" />
                        </vertical>
                    </ScrollView>
                </frame> //end

            </viewpager>
        </vertical>
    </drawer>
);
function clickUiBounds(ui) {
    if (ui.exists()) {
        var a = ui.findOne();
        if (a) {
            var b = a.bounds();
            if (b) {
                press(b.centerX(), b.centerY(),10);
                return true;
            }
        }

    }
    return false;
}
ui.lianjie.on("click", function () {
    app.openUrl("http://www.cqypp.cn:808/")
})

var 不提交订单 = "无"
var 提交订单 = "有"
ui.tijiao.on("check", (checked) => {
    if (checked) {
        不提交订单 = "有"
        提交订单 = "无"
        toast("检测商品提交价格，大于预定价格不提交！");
    }
    else {
        不提交订单 = "无"
        提交订单 = "有"
    }
});
//密码隐藏
ui.bt1.on("check", (checked) => {
    if (ui.bt1.getText() == "隐藏密码") {
        ui.bt1.setText("显示密码");
        ui.h.visibility = 8;
        toast("密码已隐藏!");
    } else {
        ui.bt1.setText("隐藏密码");
        ui.h.visibility = 0;
        toast("密码已显示!");
    }
});
//自动付款
var 自动付款 = "无"
ui.pay1.on("check", (checked) => {
    if (checked) {
        自动付款 = "有"
        toast("已开启自动付款");
    }
    else {
        自动付款 = "无"
    }
});


//这里是无障碍触发方式
ui.autoService.on("check", function (checked) {
    // 用户勾选无障碍服务的选项时，跳转到页面让用户去开启 
    if (checked && auto.service == null) {
        app.startActivity({
            action: "android.settings.ACCESSIBILITY_SETTINGS"
        });
    }
    if (!checked && auto.service != null) {
        auto.service.disableSelf();
    }
});
// 当用户回到本界面时，resume事件会被触发
ui.emitter.on("resume", function () {
    // 此时根据无障碍服务的开启情况，同步开关的状态 
    ui.autoService.checked = auto.service != null;
});
//    //开启悬浮窗权限
//     ui.overlayService.on("check", function (checked) {
//     // 用户勾选无障碍服务的选项时，跳转到页面让用户去开启
//     if (checked) {
//         int = app.startActivity({
//             packageName: "com.android.settings",
//             className: "com.android.settings.Settings$AppDrawOverlaySettingsActivity",
//             data: "package:" + auto.service.getPackageName().toString()
//         });
//         toast("请打开悬浮窗开关");
//     }

//      if (!checked && auto.service != null) {
//          auto.service.disableSelf();
//          toast("已关闭悬浮窗权限");
//          }
//     });


// 获取时分秒用于记录日志
function logWithTime(msg) {
    console.info(formatDate(getNow()) + " " + msg);
}

// 检测淘宝网络延迟和时间偏差
var NTP = {
    requiredResponses: 3,
    serverTimes: [],//服务器时间
    serverDelay: [],//服务器延迟
    serverUrl: "http://api.m.taobao.com/rest/api3.do?api=mtop.common.getTimestamp",
    resyncTime: 0, // minutes
    sync: function () {
        var offset = storage.get("NTPClockOffset");//获取时钟偏移
        if (offset) {
            try {
                var t = offset.split("|")[1];
                var d = NTP.fixTime() - parseInt(t, 10);
                if (d < (1000 * 60 * NTP.resyncTime)) {
                    return false;
                }
            } catch (e) {
            }
        }
        NTP.getServerTime();
    },
    getNow: function () {
        var date = new Date();
        return date.getTime();
    },
    //分析服务器响应
    parseServerResponse: function (data) {
        var NtpStartTime = storage.get("NtpStartTime");
        var NtpStopTime = NTP.getNow();
        var origtime = parseInt(data.data.t);//起始时间
        var delay = ((NtpStopTime - NtpStartTime) / 2);//延迟
        var offset = NtpStopTime - origtime - delay;//抵消
        NTP.serverTimes.push(offset);
        NTP.serverDelay.push(delay);

        // 因为网络问题，需要多次获取偏移值，获取平均值
        if (NTP.serverTimes.length >= NTP.requiredResponses) {
            var sumOffset = 0;
            var sumDelay = 0;
            var i = 0;
            for (i = 0; i < NTP.serverTimes.length; i++) {
                sumOffset += NTP.serverTimes[i];
                sumDelay += NTP.serverDelay[i];
            }
            var averageOffset = Math.round(sumOffset / i);
            var averageDelay = Math.round(sumDelay / i);
            storage.put("NTPClockOffset", averageOffset + '|' + NTP.fixTime()); // 保存获得offset时的时间戳
            storage.put("NTPClockDelay", averageDelay); // 保存获得offset时的时间戳
        } else {
            NTP.getServerTime();
        }
    },
    //获取服务器时间并判断是否获取成功
    getServerTime: function () {
        var NtpStartTime = NTP.getNow();
        storage.put("NtpStartTime", NtpStartTime);
        var res = http.get(NTP.serverUrl);
        if (res.statusCode !== 200) {
            toast("获取网络时间失败: " + res.statusCode + " " + res.statusMessage);
            return false;
        } else {
            NTP.parseServerResponse(res.body.json());
        }
    },
    //固定时间
    fixTime: function (timeStamp) {
        if (!timeStamp) {
            timeStamp = NTP.getNow();
        }
        var offset = storage.get("NTPClockOffset");
        try {
            if (!offset) {
                offset = 0;
            } else {
                offset = offset.split("|")[0];
            }
            if (isNaN(parseInt(offset, 10))) {
                return timeStamp;
            }
            return timeStamp + parseInt(offset, 10);
        } catch (e) {
            return timeStamp;
        }
    }
};




// 获取默认开始时间
function getTime() {
    var fmt = "YYYY-MM-dd hh:mm:ss";
    var d = new Date();
    var hh = d.getHours();
    var mm = d.getMinutes();
    var ss = d.getSeconds();
    if (mm < 30) {
        mm = 30
        ss = 00
    }
    else {
        hh += 1
        mm = 00
        ss = 00
    }

    var o = {
        "Y+": d.getYear() + 1900,
        "M+": d.getMonth() + 1,
        "d+": d.getDate(),
        "h+": hh,
        // "m+": d.getMinutes(),
        // "s+": d.getSeconds()
        "m+": mm,
        "s+": ss
    };
    for (var k in o) {
        if (new RegExp("(" + k + ")").test(fmt)) {
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 4) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        }
    }
    fmt = fmt.replace(/-/g, '/');
    return fmt;
};

//定义初始化界面数据
var storage = storages.create("tmalltaobaohelper.byfly");
threads.start(NTP.sync);

//初始化淘宝界面
setTimeout(initConfig_two, 500);
function initConfig_two() {
    NTPClockOffset = storage.get("NTPClockOffset", "0");
    NTPClockDelay = storage.get("NTPClockDelay", "0");
    if (!NTPClockOffset) {
        NTPClockOffset = 0;
    } else {
        NTPClockOffset = parseInt(NTPClockOffset.split("|")[0]);
    }
    if (NTPClockOffset < 0) {
        var offset_str = "慢了" + -NTPClockOffset + 'ms，'
    } else {
        offset_str = "快了" + NTPClockOffset + 'ms，'
    }
    if (NTPClockDelay < 50) {
        var good_str = "网速评估:" + "您的网络延迟低于50ms,非常优秀！"
    }
    else if (NTPClockDelay < 100) {
        var good_str = "网速评估:" + "您的网络延迟低于100ms,优秀！"
    }
    else if (NTPClockDelay > 100 && NTPClockDelay < 200) {
        var good_str = "网速评估:" + "您的网络延迟高于100ms,抢购可能会有影响！"
    }
    else {
        good_str = "网速评估:" + "您的网络质量不佳，建议切换网络！"
    }

    ui.networkTesttwo.on("click", function () {
        ui.networkTesttwo.setText("时间校准:" + "本地时间比淘宝" + offset_str + "已经为您校准了淘宝时间！" + '\n' + "网络延迟：" + NTPClockDelay + '\n' + good_str);
    });

    ui.startTime_two.setText(getTime());
    ui.interval.setText(storage.get("interval", "100").toString());
    ui.lastTime_two.setText(storage.get("lastTime_two", "10").toString());
    ui.delaytime_two.setText(storage.get("delaytime_two", "700").toString());
}

// 时间戳转时间字符串
function add0(m) {
    return m < 10 ? '0' + m : m
}
function getNow() {
    var now = new Date().getTime();
    return now - NTPClockOffset;
}

function formatDate(needTime) {
    //needTime是整数，否则要parseInt转换
    var time = new Date(parseInt(needTime));
    var h = time.getHours();
    var mm = time.getMinutes();
    var s = time.getSeconds();
    var S = time.getMilliseconds();
    return add0(h) + ':' + add0(mm) + ':' + add0(s) + ":" + add0(S);
}


// 检测时间字符串是否有效
function strDateTime(str) {
    var reg = /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/;
    var r = str.match(reg);
    if (r == null) return false;
    var d = new Date(r[1], r[3] - 1, r[4], r[5], r[6], r[7]);
    return (d.getFullYear() == r[1] && (d.getMonth() + 1) == r[3] && d.getDate() == r[4] && d.getHours() == r[5] && d.getMinutes() == r[6] && d.getSeconds() == r[7]);
}

var storage3 = storages.create("这个是一个文件名2");
for (i = 0; i < 7; i++) {
    var content2 = storage3.get("password_" + (i + 1));

    if (content2) {
        ui["password_" + (i + 1)].setText(content2);
    }
}

// 淘宝程序主要逻辑
ui.ok_two.click(function () {
    // 检查无障碍服务
    if (auto.service == null) {
        toast("请先开启无障碍服务！");
        return;
    }
    arr = new Array();
  


    //接收界面数据
    startTime_two = ui.startTime_two.getText().toString();
    interval = parseInt(ui.interval.getText());
    lastTime_two = parseInt(ui.lastTime_two.getText());
    delaytime_two = parseInt(ui.delaytime_two.getText());
    if (!strDateTime(startTime_two)) {
        ui.startTime_two.setError("日期错误，请重新输入！");
        return;
    }
    //传递界面数据      
    storage.put("interval", interval);
    storage.put("lastTime_two", lastTime_two);
    storage.put("delaytime_two", delaytime_two);

    //按下开始运行
    if (ui.ok_two.getText() == "开始运行") {
        ui.ok_two.setText("停止运行");
        threads.start(main_two);
        device.keepScreenOn()//保持屏幕常亮
    } else {
        ui.ok_two.setText("开始运行");
        console.clear();
        console.hide();
        threads.shutDownAll();
        device.cancelKeepingAwake();
    }

});
//这是淘宝主程序 
function main_two() {
    var middle = device.width / 2 - 400;
    console.setPosition(middle, 0);
    console.setGlobalLogConfig({ "file": "/sdcard/日志.txt" });
    console.show();
    var DetailPage = 0;
    var notDetailPage = 0;
    var notInDetailPage = 0

    threads.start(悬浮);
    function 悬浮() {
        var window = floaty.window(
            <frame gravity="center">
                <text id="text" textSize="20sp" textColor="green"  />
            </frame>
        );
    
        window.exitOnClose();
        window.setPosition((device.width/3)+30,device.height/2);
    
        window.text.click(() => {
            window.setAdjustEnabled(!window.isAdjustEnabled());
        });
        setInterval(() => {
            ui.run(function () {
                window.text.setText(dynamicText());
            });
        }, 100);
        function dynamicText() {
            var date = getNow();
            var str = util.format(formatDate(date));
            return str;
        }
        function add0(m) {
            return m < 10 ? '0' + m : m
        }
        function getNow() {
            var now = new Date().getTime();
            return now;
        }
        function formatDate(needTime) {
            //needTime是整数，否则要parseInt转换
            var time = new Date(parseInt(needTime));
            var h = time.getHours();
            var mm = time.getMinutes();
            var s = time.getSeconds();
            var S = time.getMilliseconds();
            return add0(h) + ':' + add0(mm) + ':' + add0(s) + ":" + add0(S);
        }
    }
    
    logWithTime("欢迎使用淘宝BP链接模式!");
    sleep(800);
    logWithTime("请勿用于非法用途");
    sleep(800);
    logWithTime("请打开手机淘宝，并重新切换到点击跳转页面！");
    sleep(800);
    var startTime2 = new Date(Date.parse(startTime_two)).getTime();
    var endTime = new Date(startTime2.valueOf() + lastTime_two * 1000).getTime();
    var Panicbuyingtime = startTime2 - delaytime_two;

    reviewtime();
    //判断实际时间是否大于抢购时间
    function reviewtime() {
        var tt = getNow();
        if (tt > Panicbuyingtime) {
            console.warn("您的时间已经错过了哦,请重新输入时间！");
            sleep(2000);
            console.clear();
            console.hide();
            threads.shutDownAll();
        }
        if (tt < Panicbuyingtime) {
            logWithTime("您的抢购时间为：" + formatDate(Panicbuyingtime));
            logWithTime("距离抢购时间还剩" + (startTime2 - tt) / 1000 + "秒" + "请耐心等待");
        }
    }
    // 检测是否在商品详情页
    x = setInterval(function () {
        var t = getNow();
        if (t < Panicbuyingtime) {
            //这里是消息界面1234
            //toastLog("测试密码为"+ui.password_1.text()+ui.password_2.text()+ui.password_3.text()+ui.password_4.text()+ui.password_5.text()+ui.password_6.text());
            var password_1 = ui.password_1.text();    
            var password_2 = ui.password_2.text();
            var password_3 = ui.password_3.text();
            var password_4 = ui.password_4.text();
            var password_5 = ui.password_5.text();
            var password_6 = ui.password_6.text(); 
            if (className("android.widget.RelativeLayout").depth(11).drawingOrder(5).indexInParent(2).exists() && className("android.widget.TextView").text("").exists()) {
                if (DetailPage === 0) {
                    logWithTime("已进入好友页面，并找到了跳转链接，请等待......");
                    sleep(800)
                    logWithTime("本模式需要隐藏控制台，3秒后即将隐藏控制台！");
                    logWithTime("倒计时3s")
sleep(1000)
                    logWithTime("倒计时2s");
                    sleep(1000)
                    logWithTime("倒计时1s");
                   
                    console.hide();
                    DetailPage++;
                    notDetailPage = 0
                }

            } else {
                if (notInDetailPage === 0) {
                    logWithTime("未进入好友页面，或找不到跳转链接！");
                    DetailPage = 0;
                    notInDetailPage++
                }
            }
        } else {
            not_in_Detail_Page = 0;  // 商品详情页状态复位
            clearInterval(x)
        }
    }, 500);

    z = setInterval(function () {
        var t = getNow();
        if (t >= Panicbuyingtime && t < endTime) {
            logWithTime("开始抢购")
            BP链接();
            clearInterval(z);
        }
    }, 10)
};
function BP链接() {
    var 价格值 = ui.password_7.text()
    var Crowding = 0;
    var cishu = 0;
    var endTime = lastTime_two * 1000;
/*   var password_1 = ui.password_1.text() * 1;
    var password_2 = ui.password_2.text() * 1;
    var password_3 = ui.password_3.text() * 1;
    var password_4 = ui.password_4.text() * 1;
    var password_5 = ui.password_5.text() * 1;
    var password_6 = ui.password_6.text() * 1;  */

    //如果在购物车
    var 跳转 = true
   var tiaozhuan=className("android.widget.FrameLayout").depth(10).drawingOrder(1).indexInParent(0)
    if (tiaozhuan.exists() && 跳转 != false) {
        var 跳转 = tiaozhuan.findOne()
        press(跳转.bounds().centerX(), 跳转.bounds().centerY()+300,10)
        跳转 = false
    }

    threads.start(function () {
        setInterval(function () {
            if (className("android.widget.TextView").text("加入购物车").exists()) {
                var 领卷购买 = id("com.taobao.taobao:id/detail_main_sys_button").findOne()
                press(领卷购买.bounds().centerX() + 344, 领卷购买.bounds().centerY(), 1)
            }
        }, 100);
    });

    threads.start(function () {
        setInterval(function () {
            if(className("android.widget.TextView").text("领券购买").exists()){
                var 继续 = className("android.widget.TextView").text("领券购买").findOne()
                press(继续.bounds().centerX(), 继续.bounds().centerY(),10)
            }
            
            if(className("android.widget.TextView").text("确认").exists()){
                var 继续购 = className("android.widget.TextView").text("确认").findOne()
                press(继续购.bounds().centerX(), 继续购.bounds().centerY(),10)
            }
            if(className("android.widget.TextView").text("确定").exists()){
                var 继续购买 = className("android.widget.TextView").text("确定").findOne()
                press(继续购买.bounds().centerX(), 继续购买.bounds().centerY(),10)
            }
        }, 100);
    });

    if (不提交订单 == "有") {
        var 校验价格 = "真"
        if (校验价格 == "真") {
            threads.start(function () {
                setInterval(function () {
                    if (className("android.widget.TextView").text("￥" + 价格值).depth(12).exists() && className("android.widget.TextView").text("提交订单").exists()) {
                        logWithTime("已找到符合预定价格的商品，开始提交订单！");
                        className("android.widget.TextView").text("提交订单").findOne().click();
                        找到了 = "真"
                    }
                    else if (className("android.widget.TextView").text("提交订单").exists()) {
                        logWithTime("没有找到符合预定价格的商品，不提交订单！");
                        Panic_buying_end()
                    }
                }, 200)
            })
        }
    }


    if (提交订单 == "有") {
        threads.start(function () {
            setInterval(function () {
                if (className("android.widget.TextView").text("提交订单").exists()) {
                    logWithTime("正在尝试提交订单");
                    className("android.widget.TextView").text("提交订单").findOne().click();
                    logWithTime("订单已提交");
                }
            }, 10)
        })
    }
    threads.start(function () {
        setInterval(function () {
            if (className("android.widget.TextView").textContains("加载中").exists()) {
                if (Crowding === 0) {
                    Crowding = 1
                    logWithTime("页面加载中");
                }
            }
        }, 10)
    })
    threads.start(function () {
        setInterval(function () {
            if (className("android.widget.TextView").text("我知道了").exists()) {
                className("android.widget.TextView").text("我知道了").findOne().click();
                found = true;
                cishu++;
                logWithTime("第" + cishu + "次拥挤了，再试一次吧！");
            }
        }, 10)
    })
    threads.start(function () {
        setInterval(function () {
            if (className("android.widget.TextView").text("立即付款").exists()) {
                if (自动付款 == "无") {
                    logWithTime("抢购成功！请支付！");
                    device.cancelKeepingAwake();
                    Panic_buying_end()
                }
            }
            if (自动付款 == "有") {
                click("立即付款")
                
            }
        }, 200)
    })

    threads.start(function(){
        setInterval(function(){
   
  // var 自动付款 ="有"
//1234
        var 密码1 = "真"
        var 密码2 = "假"
        var 密码3 = "假"
        var 密码4 = "假"
        var 密码5 = "假"
        var 密码6 = "假"
        threads.start(function(){
            setInterval(function(){ 
                click("立即付款")
            if (className("android.widget.TextView").text("请输入支付密码").exists()) { 
                if(密码1 == "真"&&className("android.widget.TextView").text(password_1).exists()){clickUiBounds(password_1);密码2 = "真";sleep(20)}
                if(密码2 == "真"&&className("android.widget.TextView").text(password_2).exists()){clickUiBounds(password_2);密码3 = "真";sleep(20)}
                if(密码3 == "真"&&className("android.widget.TextView").text(password_3).exists()){clickUiBounds(password_3);密码4 = "真";sleep(20)}
                if(密码4 == "真"&&className("android.widget.TextView").text(password_4).exists()){clickUiBounds(password_4);密码5 = "真";sleep(20)}
                if(密码5 == "真"&&className("android.widget.TextView").text(password_5).exists()){clickUiBounds(password_5);密码6 = "真";sleep(20)}
                if(密码6 == "真"&&className("android.widget.TextView").text(password_6).exists()){clickUiBounds(password_6);Panic_buying_end()}
            } 
        },300)
        })
    //1234
    device.cancelKeepingAwake(); 
    //Panic_buying_end();             

}, 10);
});

    threads.start(function () {
        setInterval(function () {
            if (className("android.view.View").desc("支付成功").exists()) {
                logWithTime("支付成功！");
                Panic_buying_end()
            }
        }, 10)
    })
    threads.start(function () {
        setInterval(function () {
            sleep(endTime)
            logWithTime("超出预定抢购时长，抢购结束");
            device.cancelKeepingAwake();
            Panic_buying_end();

        }, 10)
    })
}

function Panic_buying_end() {
    device.cancelKeepingAwake()//关闭屏幕常亮
    logWithTime("本次抢购结束");
    threads.shutDownAll()
}
